#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (i=l; i<=r; i++)
#define For(i,x) for (i=h[x]; i; i=e[i].nxt) if (!vis[k=e[i].to] && k!=fa)
using namespace std;

const int N=20010,inf=0x3f3f3f3f;
int i,n,x,y,v,cnt,k,tot,rt,sum,ans,fa=0,h[N],f[N],vis[N],sz[N],d[N],a[N];
struct E{ int to,val,nxt; } e[N];
void add(int u,int v,int w){ e[++cnt]=(E){v,w,h[u]}; h[u]=cnt; }

void get(int x,int fa){
    int i,k; sz[x]=1; f[x]=0;
    For(i,x) get(k,x),sz[x]+=sz[k],f[x]=max(f[x],sz[k]);
    f[x]=max(f[x],sum-sz[x]);
    if (f[x]<f[rt]) rt=x;
}

void deep(int x,int fa){
    int i,k; a[++tot]=d[x];
    For(i,x) d[k]=d[x]+e[i].val,deep(k,x);
}

int cal(int x,int v){
    d[x]=v; tot=0; deep(x,0);
    sort(a+1,a+tot+1);
    int l=1,r=tot,sum=0;
    while (l<r)
        if (a[l]+a[r]<=k) sum+=r-l,l++; else r--;
    return sum;
}

void solve(int x){
    int i,k; ans+=cal(x,0); vis[x]=1;
    For(i,x){
        ans-=cal(k,e[i].val); sum=sz[k];
        rt=0; get(k,0); solve(rt);
    }
}

int main(){
    for (scanf("%d%d",&n,&k); n+k; scanf("%d%d",&n,&k)){
        ans=rt=cnt=0; f[0]=inf; sum=n;
        memset(vis,0,sizeof(vis)); memset(h,0,sizeof(h));
        rep(i,1,n-1) scanf("%d%d%d",&x,&y,&v),add(x,y,v),add(y,x,v);
        get(1,0); solve(rt); printf("%d\n",ans);
    }
    return 0;
}

//Dynamic:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rg register int
#define rep(i,l,r) for (rg i=l; i<=r; i++)
#define For(i,x) for (int i=h[x],k; i; i=nxt[i])
typedef long long ll;
using namespace std;

const int N=100100,M=6000100,inf=1000000000;
int n,m,rt,S,op,x,y,lst,tot,nd,cnt,to[N<<1],nxt[N<<1],h[N];
int sz[N],fa[N],vis[N],st[20][N<<1],dep[N];
int pos[N],root[N],root1[N],lg[N<<1],f[N],a[N],sum[M],ls[M],rs[M];

template<typename T>inline void rd(T &x){
    rg t; char ch;
    for (t=0; !isdigit(ch=getchar()); t=(ch=='-'));
    for (x=ch-'0'; isdigit(ch=getchar()); x=x*10+ch-'0');
    if (t) x=-x;
}

void add(rg u,rg v){ to[++cnt]=v; nxt[cnt]=h[u]; h[u]=cnt; }

void find(rg x,rg fa){
    sz[x]=1; f[x]=0;
    For(i,x) if ((k=to[i])!=fa && !vis[k])
    find(k,x),sz[x]+=sz[k],f[x]=max(f[x],sz[k]);
    f[x]=max(f[x],S-sz[x]);
    if (f[x]<f[rt]) rt=x;
}

void dfs(rg x,rg fa){
    st[0][++tot]=dep[x]; pos[x]=tot;
    For(i,x) if ((k=to[i])!=fa)
        dep[k]=dep[x]+1,dfs(k,x),st[0][++tot]=dep[x];
}

void rmq(){
    rep(j,1,18) rep(i,1,tot-(1<<j)+1)
        st[j][i]=min(st[j-1][i],st[j-1][i+(1<<(j-1))]);
}

int get(rg l,rg r){
    if (l>r) swap(l,r); rg t=lg[r-l+1];
    return min(st[t][l],st[t][r-(1<<t)+1]);
}

int dis(rg u,rg v){ rg x=pos[u],y=pos[v]; return dep[u]+dep[v]-2*get(x,y); }

void mdf(rg &x,rg L,rg R,rg pos,rg k){
    if (!x) x=++nd;
    sum[x]+=k; if (L==R) return;
    rg mid=(L+R)>>1;
    if (pos<=mid) mdf(ls[x],L,mid,pos,k); else mdf(rs[x],mid+1,R,pos,k);
}

int que(rg x,rg L,rg R,rg pos){
    if (!x) return 0;
    if (L==R) return sum[x];
    rg mid=(L+R)>>1;
    if (pos<=mid) return que(ls[x],L,mid,pos);
        else return sum[ls[x]]+que(rs[x],mid+1,R,pos);
}

void work(rg x,rg F,rg p){
    mdf(root[p],0,n,dis(x,p),a[x]);
    if (fa[p]) mdf(root1[p],0,n,dis(x,fa[p]),a[x]);
    For(i,x) if (!vis[k=to[i]] && k!=F) work(k,x,p);
}

void build(rg x){
    vis[x]=1; work(x,fa[x],x);
    for (rg i=h[x],k; i; i=nxt[i]) if (!vis[k=to[i]])
        f[rt=0]=inf,S=sz[k],find(k,x),fa[rt]=x,build(rt);
}

int getans(rg x,rg y){
    rg res=que(root[x],0,n,y); rg D=0;
    for (rg i=x; fa[i]; i=fa[i]){
        D=dis(x,fa[i]);
        if (D>y) continue;
        if (D-y>20) return x;
        res+=que(root[fa[i]],0,n,y-D)-que(root1[i],0,n,y-D);
    }
    return res;
}

void modify(rg x,rg y){
    int t=y-a[x]; mdf(root[x],0,n,0,t); a[x]=y;
    for (int i=x; fa[i]; i=fa[i]){
        mdf(root[fa[i]],0,n,dis(x,fa[i]),t);
        mdf(root1[i],0,n,dis(x,fa[i]),t);
    }
}

int main(){
    freopen("bzoj3730.in","r",stdin);
    freopen("bzoj3730.out","w",stdout);
    rd(n); rd(m);
    rep(i,1,n) rd(a[i]);
    rep(i,1,n-1) rd(x),rd(y),add(x,y),add(y,x);
    dfs(1,0); rmq();
    lg[1]=0; rep(i,2,tot) lg[i]=lg[i>>1]+1;
    f[rt=0]=inf; S=n; find(1,0); build(rt);
    rep(i,1,m){
        rd(op); rd(x); rd(y); x^=lst; y^=lst;
        if (op==0) printf("%d\n",lst=getans(x,y)); else modify(x,y);
    }
    return 0;
}